﻿using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Castle.DynamicProxy;

namespace E_Commerce.Common.Log4net
{
    /// <summary>
    /// Server层的拦截器
    /// </summary>
    public class ServerInterceptor:IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            //记录日志
            string logMsg = $"方法开始于{DateTime.Now}\n";
            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                _ = $"方法中抛出异常：{ex.Message + ex.InnerException}\n";
                throw;
            }
            logMsg += $"方法结束于{DateTime.Now}\n";
            Log4netHelper.Info(logMsg);
        }
    }
}
